package com.heima.controller;


import com.heima.common.PageResult;
import com.heima.pojo.Node;
import com.heima.pojo.User;
import com.heima.pojo.dto.NodeDTO;
import com.heima.pojo.dto.NodePageQueryDTO;
import com.heima.pojo.vo.VmListVo;
import com.heima.service.NodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/vm-service/node")
public class NodeController {

    @Autowired
    private NodeService nodeService;

    @GetMapping("/search")
    public PageResult regionQuery(NodePageQueryDTO dto){
        log.info("查看区域详情：{}",dto);
        return nodeService.regionQuery(dto);
    }

    @PostMapping
    public Boolean save(@RequestBody Node node){
        log.info("新增点位：{}",node);
        return nodeService.save(node);
    }

    @GetMapping("vmList/{nodeId}")
    public List<VmListVo> nodeFindById(@PathVariable Integer nodeId){
        log.info("获取点位详情：{}",nodeId);
        return nodeService.nodeFindById(nodeId);
    }

    @PutMapping("/{nodeId}")
    public Boolean updateNode(@PathVariable Integer nodeId,@RequestBody NodeDTO dto){
        log.info("修改点位：{},{}",nodeId,dto);
        return nodeService.updateNode(nodeId,dto);
    }

    @DeleteMapping("/{nodeId}")
    public Boolean deleteById(@PathVariable Integer nodeId) {
        log.info("删除点位：{}", nodeId);
        return nodeService.deleteById(nodeId);
    }

    @GetMapping("/count")
    public Integer nodeCount(){
        log.info("点位数量：");
        return nodeService.nodeCount();
    }
}
